package com.example.tms.mapper;

import com.example.tms.bean.CarInfo;
import com.example.tms.bean.UserInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * 用户信息
 */
@Repository
public interface UserMapper extends JpaRepository<UserInfo, String>, JpaSpecificationExecutor<UserInfo> {

    //查询用户信息（用户id）
    @Query(value = "select * from user_info where yhid = ?1 and sfcz = true", nativeQuery = true)
    UserInfo findByYhid(String yhid);

    //查询用户信息（部门id）
    @Query(value = "select * from user_info where bumenid = ?1 and sfcz = true", nativeQuery = true)
    List<UserInfo> findByBumenid(String bumenid);

    //查询用户信息（用户名）
    @Query(value = "select * from user_info where yhm = ?1 and sfcz = true", nativeQuery = true)
    UserInfo findByYhm(String yhm);

    //查询用户信息（用户名）
    @Query(value = "select * from user_info where sjh = ?1 and sfcz = true", nativeQuery = true)
    UserInfo findBySjh(String sjh);

    //删除用户信息（假删除 用户id）
    @Query(value = "update user_info set sfcz = false where yhid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void DeleteByYhid(String yhid);


    //修改密码

    @Query(value = "update user_info set mima = ?2 where yhid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void UpdateMima( String yhid,String xmm);


    //修改审核状态
    @Query(value = "update user_info set shzt = ?1 where yhm = ?2", nativeQuery = true)
    @Modifying
    @Transactional
    void upDateShzt(String shzt,String yhm);
}
